package com.xxx.tomcat;

import java.nio.charset.Charset;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServer;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.stereotype.Component;

@Component
public class LocalEmbeddedServletContainerFactory  extends TomcatServletWebServerFactory {

//	@Override
//    public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers)
//    {
//        //设置端口
//        //this.setPort(8087);
//    	this.setUriEncoding(Charset.forName("UTF-8"));
//        return super.getEmbeddedServletContainer(initializers);
//    }

    @Override
    public WebServer getWebServer(ServletContextInitializer... initializers){
        //设置端口
        //this.setPort(8087);
        this.setUriEncoding(Charset.forName("UTF-8"));
        return super.getWebServer(initializers);
    }
	@Override
    protected void customizeConnector(Connector connector)
    {
        super.customizeConnector(connector);
        Http11NioProtocol protocol = (Http11NioProtocol)connector.getProtocolHandler();
        //设置最大连接数
        protocol.setMaxConnections(2000);
        //设置最大线程数
        protocol.setMaxThreads(2000);
        protocol.setConnectionTimeout(30000);
    }
}
